﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ZX.DAL.DBExtend;
using System.Data.SqlClient;

namespace ZX.CRM.Bussiness
{
    public class BCrmValue
    { 
        /// <summary>
        /// 获取价值业绩统计结果                
        /// </summary>
        /// <param name="sdate"></param>
        /// <param name="edate"></param>
        /// <returns></returns>
        public DataTable ReturnDsValue(string sdate, string edate, string procName)
        {
            DataSet ds = new DataSet();
            DbSql execsql = new DAL.DBExtend.DbSql();
            IDataParameter[] _Parameters = new IDataParameter[] { };
            SqlParameter spSdate = new SqlParameter("@sdate", SqlDbType.NVarChar, 50);
            spSdate.Direction = ParameterDirection.Input;
            spSdate.Value = sdate;
            SqlParameter spEdate = new SqlParameter("@edate", SqlDbType.NVarChar, 50);
            spEdate.Direction = ParameterDirection.Input;
            spEdate.Value = edate;
            _Parameters = new IDataParameter[] { spSdate ,spEdate};
            ds = execsql.RunProcedure(procName, _Parameters, true);
            return (ds==null||ds.Tables.Count==0)?null:ds.Tables[0];
        }
        /// <summary>
        /// 获取排名统计结果                
        /// </summary>
        /// <param name="sdate">开始日期</param>
        /// <param name="edate">结束日期</param>
        /// <param name="type">具体类型：0分公司，1分总，2团队，3个人</param>
        /// <returns></returns>
        public DataTable ReturnDsSort(string type,string sdate, string edate, string procName)
        {
            DataSet ds = new DataSet();
            DbSql execsql = new DAL.DBExtend.DbSql();
            IDataParameter[] _Parameters = new IDataParameter[] { };
            SqlParameter spType = new SqlParameter("@stype", SqlDbType.Char, 1);
            spType.Direction = ParameterDirection.Input;
            spType.Value = type;
            SqlParameter spSdate = new SqlParameter("@sdate", SqlDbType.DateTime, 10);
            spSdate.Direction = ParameterDirection.Input;
            spSdate.Value = DateTime.Parse(sdate);
            SqlParameter spEdate = new SqlParameter("@edate", SqlDbType.DateTime, 10);
            spEdate.Direction = ParameterDirection.Input;
            spEdate.Value =DateTime.Parse(edate);
            _Parameters = new IDataParameter[] { spType, spSdate, spEdate };
            ds = execsql.RunProcedure(procName, _Parameters, true);
            return (ds == null || ds.Tables.Count == 0) ? null : ds.Tables[0];
        }
        /// <summary>
        /// 获取首页排名权限               
        /// </summary>
        /// <param name="sdate"></param>
        /// <param name="edate"></param>
        /// <returns></returns>
        public DataTable ReturnDsSort(string userId,string procName)
        {
            DataSet ds = new DataSet();
            DbSql execsql = new DAL.DBExtend.DbSql();
            IDataParameter[] _Parameters = new IDataParameter[] { };
            SqlParameter spUserID = new SqlParameter("@UserID", SqlDbType.UniqueIdentifier, 50);
            spUserID.Direction = ParameterDirection.Input;
            spUserID.Value =new Guid(userId);

            _Parameters = new IDataParameter[] { spUserID };
            ds = execsql.RunProcedure(procName, _Parameters, true);
            return (ds == null || ds.Tables.Count == 0) ? null : ds.Tables[0];
        }
    }
}
